//
//  GarbageSearchService.swift
//  Community
//
//  Created by MAC on 2019/8/5.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit
import AVFoundation
extension SWPTHomeViewController{

    func requestCamara() {
        
        AVCaptureDevice.requestAccess(for: .video) { (granted) in
            DispatchQueue.main.async {
                if granted {
                    
                }else {
                    let alertVC = UIAlertController.init(title: "提示", message: "您还未允许App访问摄像头，请在iPhone的'设置-隐私-照片'选项中\n允许访问你的相机", preferredStyle: .alert)
                    let cancel = UIAlertAction.init(title: "好的", style: .cancel, handler: nil)
                    alertVC.addAction(cancel)
                    UIApplication.shared.keyWindow?.rootViewController?.present(alertVC, animated: true, completion: nil)
                }
            }
        }
    }
    
    func loadCamara() {
        let imagePicker = UIImagePickerController.init()
        imagePicker.delegate = self
        imagePicker.allowsEditing = true
        imagePicker.sourceType = .camera
        UIApplication.shared.keyWindow?.rootViewController?.present(imagePicker, animated: true, completion: nil)
    }
}
extension SWPTHomeViewController: UIImagePickerControllerDelegate,UINavigationControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        
        let type = info[UIImagePickerController.InfoKey.mediaType] as! String
        if type == "public.image"  {
            let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
            requestAI(image)
        }
    }
    
    func requestAI(_ image: UIImage) {
        
    }
}
